package com.dduggs.activemq.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class AppConsumer {

    private static final String url="tcp://127.0.0.1:61616";
    private static final String topicName="queue-test";

    public static void main(String[] args) {
        ConnectionFactory connectionFactory=new ActiveMQConnectionFactory(url);
        Connection connection= null;
        try {
            connection = connectionFactory.createConnection();
            connection.start();
            Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);

            Destination destination= session.createTopic(topicName);

            MessageConsumer consumer=session.createConsumer(destination);
            consumer.setMessageListener(new MessageListener() {
                @Override
                public void onMessage(Message message) {
                    TextMessage textMessage= (TextMessage) message;
                    try {
                        System.out.println("receive ==="+textMessage.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            });

//            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
